The blanks are filled in below:
class ButtonFrame2 extends JFrame implements ActionListener { JButton bChange ; // constructor public ButtonFrame2(String title) { super( title ); setLayout( new FlowLayout() ); bChange = new JButton("Click Me!"); add( bChange ); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } // listener method required by the interface public void actionPerformed( ActionEvent evt) { . . . . . . } }
In this style of GUI programming,
one object (the ButtonFrame
object) is playing two roles:
it is the container object that holds a GUI component,
and it is also the listener object for that component.
Implementing ActionListener
is not enough.
The listener must still be registered with the JButton
.
(Review: ) What does registering a listener do?